<?php
// $Id: throttle.admin.inc,v 1.2 2008/01/08 10:35:43 goba Exp $

/**
 * @file
 * Admin page callbacks for the throttle module.
 */

/**
 * Form builder; Configure the throttle system.
 *
 * @ingroup forms
 * @see system_settings_form()
 * @see throttle_admin_settings_validate()
 */
function ec_scarab_admin_settings() {
	$form['ec_scarab_merchant_code'] = array(
		'#type' => 'textfield',
		'#title' => t('Scarab merchant code'),
		'#default_value' => variable_get('ec_scarab_merchant_code', ''),
		'#size' => 20,
		'#maxlength' => 64,
		'#description' => t('merchant code for the scarab recommendation system')
	);
	$form['ec_scarab_merchant_pass'] = array(
		'#type' => 'password',
		'#title' => t('Scarab merchant password'),
		'#default_value' => variable_get('ec_scarab_merchant_pass', ''),
		'#size' => 20,
		'#maxlength' => 64,
		'#description' => t('merchant password for the scarab recommendation system')
	);
	$form['#validate'] = array('ec_scarab_admin_settings_validate');

	if (variable_get('ec_scarab_merchant_code', '')
		&& variable_get('ec_scarab_merchant_pass', ''))
	{
		$form['hspace'] = array( '#type' => 'markup', '#value' => '<br/>', '#weight'=>199);
		$form['upload_product'] = array(
			'#type' => 'button',
			'#submit' => array('ec_scarab_manual_products_upload_wrapper'),
			'#value' => t('Upload product data'),
			'#weight' => 200,
			'#executes_submit_callback' => TRUE
		);
		$form['upload_history'] = array(
			'#type' => 'button',
			'#submit' => array('ec_scarab_manual_historical_upload_wrapper'),
			'#value' => t('Upload historical data'),
			'#weight' => 200,
			'#executes_submit_callback' => TRUE
		);
	}

	$form['link_to_scr'] = array('#type' => 'markup', '#value' => '<br/><a href="https://admin.scarabresearch.com/">'.t('Scarab Admin UI').'</a>', '#weight'=>300 );
	$f =  system_settings_form($form);
	return $f;
}

function ec_scarab_admin_settings_validate($form, &$form_state) {
	if (!$form_state['values']['ec_scarab_merchant_pass']) {
		$form_state['values']['ec_scarab_merchant_pass'] = variable_get('ec_scarab_merchant_pass', '');
	}
}
